layui.use(['form', 'element', 'util','layer'], function(){
    var form = layui.form,
        element = layui.element,
        util = layui.util,
        layer = layui.layer,
        $ = layui.$;

    /**
     * 右下角固定条
     */
    util.fixbar({
        bar1: true,
        click: function(type){
            if(type === 'bar1'){
                alert('点击了bar1')
            }
        }
    });

    /**
     * 登录框
     */
    var $showLoginBox = $("#show-login-box");
    $showLoginBox.click(function () {
        var $loginBox = $('#login-box');
        var $loginForm = $loginBox.find('.layui-form');
        layer.open({
            type: 1,
            title: '',
            shade : 0.5,
            resize: false,
            area : ['400px','310px'],
            content: $loginBox.find(".l-login-area"),
            success: function () {
                $loginBox.removeClass("layui-hide")
            },
            end: function() {
                form.val('loginForm', {
                    'account': '',
                    'password': '',
                    'autoLogin': false
                });
                $showLoginBox.removeClass('layui-this');
                $loginBox.addClass("layui-hide");
            }
        });
    });

    /**
     * 注册框
     */
    var $showRegisterBox = $("#show-register-box");
    $showRegisterBox.click(function () {
        var $registerBox = $('#register-box');
        var $registerForm = $registerBox.find('.layui-form');
        layer.open({
            type: 1,
            title: '',
            shade : 0.5,
            resize: false,
            area : ['400px','463px'],
            content: $registerBox.find(".l-register-area"),
            success: function () {
                $registerBox.removeClass("layui-hide")
            },
            end: function() {
                $registerForm.find('input').val('');
                $showRegisterBox.removeClass('layui-this');
                $registerBox.addClass("layui-hide");
            }
        });
    });
    /**
     * md 转换
     */
    var $mdshow = $(".j-md-html");
    $(".j-md").each(function (i,self) {
        var parser = new HyperDown,
        $html = $($mdshow[i]);
        self.onkeydown=function () {
            $html.html(parser.makeHtml(self.value));
        }
        self.onkeyup = function () {
            $html.html(parser.makeHtml(self.value));
        }
    })
});